package com.cmc.cloud.cmclink.doc.util.so;

import com.cmc.cloud.cmclink.common.filter.FilterGroup;
import com.cmc.cloud.cmclink.common.filter.FilterInfo;
import com.cmc.cloud.cmclink.expression.AviatorInstanceHolder;
import com.cmc.cloud.cmclink.expression.CmclinkExpression;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * PDF生成工具类
 *
 * @author chenzheng
 * @date 2025/08/01 11:25
 */

@Slf4j
public class CmclinkExpressionUtil {
    static {
        AviatorInstanceHolder.initByScan();
    }

    public static boolean check(FilterGroup filterGroup, Map<String, Object> valueMap) {
        FilterInfo filterInfo = new FilterInfo();
        filterInfo.setFilterGroup(filterGroup);
        String exeString = FilterExprBuilderNew.build(filterInfo);
        if (StringUtils.isEmpty(exeString)) {
            return true;
        }
        CmclinkExpression exe = new CmclinkExpression(exeString);
        boolean check = (boolean) exe.evaluate(valueMap);
        log.info("原始Expr: {}  结果 {}", exeString, check);
        return check;
    }
}
